package com.intellagric.controller.module.trace_field;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.traceability.FieldVo;
import com.intellagric.pojo.TraceField;
import com.intellagric.service.traceability.trace_field.FieldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/11/9
 * @DESC： 场地信息管理
 */
@Controller
public class FieldController {

    @Autowired
    private FieldService fieldService;

    /**
     * 添加场地信息
     * @Param field
     * @return ResponseMessage
     */
    @RequestMapping("/field/add")
    @ResponseBody
    public ResponseMessage add(TraceField field) {
        field.setId(UUID.randomUUID().toString().replaceAll("-",""));
        field.setCreateDate(new Date());
        field.setUpdateDate(new Date());
        return fieldService.addField(field);
    }

    /**
     * 删除场地信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/field/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return fieldService.deleteField(id);
    }

    /**
     * 修改场地信息
     * @Param field
     * @return ResponseMessage
     */
    @RequestMapping("/field/edit")
    @ResponseBody
    public ResponseMessage edit(TraceField field) {
        field.setUpdateDate(new Date());
        return fieldService.editField(field);
    }

    /**
     * 查询场地信息
     * @return TraceField
     */
    @RequestMapping("/field/{id}")
    @ResponseBody
    public TraceField get(@PathVariable String id) {
        return fieldService.getFieldById(id);
    }

    /**
     * 查询场地信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/field/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return fieldService.getFieldList();
    }

    /**
     * 分页查询场地信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/field/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return fieldService.getFieldPage(page,limit);
    }

    /**
     * 分页查询场地信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/field/pageByCreateBy")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit,String createBy) {
        return fieldService.getFieldPage(page,limit,createBy);
    }
    /**
     * 根据VO类查询场地信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/field/query")
    @ResponseBody
    public LayuiDataGridResult getByVo(FieldVo fieldVo) {
        return fieldService.getFieldByVo(fieldVo);
    }

    /**
     * 根据VO类查询场地信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/field/queryPage")
    @ResponseBody
    public LayuiDataGridResult getByVo(int page,int limit,FieldVo fieldVo) {
        return fieldService.getFieldByVo(page,limit,fieldVo);
    }

}
